package com.lagou.homework4.no3;

import java.io.*;

/**
 * 文件拷贝
 * file1 被拷贝的文件路径
 * file2 拷贝后的文件路径
 */
public class FileCopy {
    public static void fileCopy(String file1,String file2){
        BufferedInputStream is = null;
        BufferedOutputStream os = null;
        try {
            is = new BufferedInputStream(new FileInputStream(file1));
            os = new BufferedOutputStream(new FileOutputStream(file2));
            byte[] bArr = new byte[1024];
            int res = 0;
            while ((res=is.read(bArr))!=-1){
                os.write(bArr, 0, res);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(null!=is){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(null!=os){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
